package com.ruibang.glass.quality.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruibang.glass.quality.domain.req.DiscardDefectReq;
import com.ruibang.glass.quality.domain.req.EverydayDiscardDefectReq;
import com.ruibang.glass.quality.entity.EverydayHotEndDiscardDefect;
import com.ruibang.glass.quality.mapper.EverydayHotEndDiscardDefectMapper;
import com.ruibang.glass.quality.service.EverydayHotEndDiscardDefectService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: songJinKang
 * @CreateTime: 2023-09-05  11:36
 * @Description: TODO
 * @Version: 1.0
 */

@Service
@Slf4j
public class EverydayHotEndDiscardDefectServiceImpl extends ServiceImpl<EverydayHotEndDiscardDefectMapper, EverydayHotEndDiscardDefect> implements EverydayHotEndDiscardDefectService {


    /**
     * @Description: 删除数据
     * @version v1.0
     * @author songJinKang
     * @date 2023-09-06 10:26
     */
    @Override
    public void deleteByDate(DiscardDefectReq defectReq) {
        baseMapper.deleteByDate(defectReq);
    }


    /**
     * @Description: 查询每日判废缺陷数量及曲线(热端)
     * @version v1.0
     * @author songJinKang
     * @date 2023-09-06 14:46
     */
    @Override
    public ResultBody queryEverydayDiscardDefect(EverydayDiscardDefectReq everydayDiscardDefectReq) {
        List<EverydayHotEndDiscardDefect> everydayDiscardDefectList = baseMapper.queryEverydayDiscardDefect(everydayDiscardDefectReq);
        everydayDiscardDefectList = everydayDiscardDefectList.stream().sorted(Comparator.comparing(EverydayHotEndDiscardDefect::getDiscardDate).reversed()).collect(Collectors.toList());
        return ResultBody.success(everydayDiscardDefectList);
    }
}
